<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Book_Category extends Controller{

protected $_book_category;

public function action_index()
{
}

public function action_list()
{
	$query_result = ORM::factory('category')->where('status', '=', 'on')->order_by('order', 'DESC')->find_all();
	$result = Book_Category::instance()->create_category_list($query_result->as_array());
	json_Output::write($result);
}

public function action_image()
{
	$category_id = arr::get($_GET, 'category_id');
	if ($category_id == NULL)
	{
		header("Status: 400 参数为空");
		return;
	}

	$category = ORM::factory('category')->where('id', '=', $category_id)->find();
	if (!$category->loaded())
	{
		header("Status: 400 类别id不存在");
		return;
	}
	
	if ($image = $category->get_image())
	{
		Book_Picture::instance()->render_thumb($image);
		return;
	}
}

public function action_thumbnail()
{
	$category_id = arr::get($_GET, 'category_id');
	if ($category_id)
    {
		$category = ORM::factory('category')->where('id', '=', $category_id)->find();
		if ($category->loaded())
		{
			Book_Category::instance()->render_thumb($category->image);
		}
		else
		{
			header("Status: 400 类别id不存在");
			return;
		}
	}
	else
	{
		header("Status: 400 参数为空");
		return;
	}
}

}


